<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" %>


<%
    String path = request.getContextPath();
    String basepath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
    session.removeAttribute("userName");
    session.removeAttribute("id");
    session.removeAttribute("iden");

    if (request.getAttribute("userName") == null && request.getAttribute("password") == null) {
        String username = null;
        String password = null;
        Cookie[] cookies = request.getCookies();
        for (int i = 0; cookies != null && i < cookies.length; i++) {
            if (cookies[i].getName().equals("userCookie")) {
                username = cookies[i].getValue().split("-")[0];
                password = cookies[i].getValue().split("-")[1];
            }
        }
        if (username == null) {
            username = "";
        }
        if (password == null) {
            password = "";
        }
        pageContext.setAttribute("userName", username);
        pageContext.setAttribute("pwd", password);
    }
%>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>读者用户登录界面</title>
    <link rel="stylesheet" type="text/css" href="css/login.css"/>
    <%--		boostrap引入--%>
    <link rel="stylesheet" href="css/bootstrap/css/bootstrap.css">
</head>
<body>
<div id="login">
    <div id="login_top">
        <img src="img/cc27dbf0927f9af0ed4c0d0fdfb3861.png"/> 鲸祺书屋
    </div>
    <div id="login_content">
        <form action="Test2" id="loginForm" method="post">
            <div>
                <label><strong>账号:</strong></label>
                <input type="text" name="uname" id="uname" value="${userName}"/>
            </div>
            <div>
                <strong>密码：</strong>
                <input type="password" name="upwd" id="upwd" value="${pwd}"/>
            </div>
            <div id="forget">
                <a href="#">忘记密码？</a>
                <a href="Register.jsp" id="submit" style="text-decoration: underline;">还没有账号？立即注册</a>
            </div>
            <input id=" remember" name="remember" type="checkbox" value="remember-me">记住我 &nbsp;&nbsp;&nbsp;&nbsp;
                <span style="color:red">${errorMsg}</span>
                <div id="login_footer">
                    <input type="button" id="loginBtn" value="登录" style="background-color: dodgerblue"/><br>
                    <span style="color: red;font-size: 12px" id="msg">${requestScope.msg}</span>
                    <div id="login_footer_content">
                        用户系统已升级，在登录或注册期间，如果遇到问题，请发送邮件至<a href="#">xiehousw@nlc.com</a>,我们会定位您的问题并帮您解决。
                    </div>
                </div>
        </form>
    </div>
</div>
</body>
<script type="text/javascript" src="js/jquery-2.1.0.js"></script>
<script language="JavaScript" type="text/javascript">
    $("#loginBtn").click(function () {
        //获取用户名姓名和密码
        var uname = $("#uname").val();
        var upwd = $("#upwd").val();
        //判断姓名是否为空
        if (isEmpty(uname)) {
            //如果姓名为空，提示用户（span标签赋值），并且return html（）
            $("#msg").html("用户姓名不可为空");
            return;
        }
        //判断是否为空
        if (isEmpty(upwd)) {
            //如果密码为空，提示用户（span标签赋值），并且return html（）
            $("#msg").html("密码不可为空");
            return;
        }
        //如果都不为空，则手动提交表单
        $("#loginForm").submit();

    });

    //判断字符串是否为空
    function isEmpty(str) {
        if (str == null || str.trim() == "") {
            return true;
        }
        return false;
    }
</script>

</html>